package com.wanmait.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.Company;
import com.wanmait.employment.entity.CompanyProductIntroduction;
import com.wanmait.employment.mapper.CompanyMapper;
import com.wanmait.employment.mapper.CompanyProductIntroductionMapper;
import com.wanmait.employment.service.CompanyProductIntroductionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CompanyProductIntroductionServiceImpl implements CompanyProductIntroductionService {
    @Resource
    private CompanyProductIntroductionMapper companyProductIntroductionMapper;
    @Resource
    private CompanyMapper companyMapper;

    @Override
    public PageInfo<CompanyProductIntroduction> selectList(String title, int pageNum, int passSize) {
        PageHelper.startPage(pageNum,passSize);
        QueryWrapper<CompanyProductIntroduction> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("title",title).or().inSql("company_id", "SELECT id FROM  company where company_name like '%"+title+"%'");
        List<CompanyProductIntroduction> companyProductIntroductions=companyProductIntroductionMapper.selectList(queryWrapper);
        PageInfo<CompanyProductIntroduction>companyProductIntroductionPageInfo=new PageInfo<>(companyProductIntroductions);
        companyProductIntroductionPageInfo.getList().forEach((companyProductIntroduction -> {
            QueryWrapper<Company>companyQueryWrapper=new QueryWrapper<>();
            companyQueryWrapper.eq("id",companyProductIntroduction.getCompanyId());
            Company company=companyMapper.selectOne(companyQueryWrapper);
            companyProductIntroduction.setCompany(company);
        }));
        return companyProductIntroductionPageInfo;
    }

    @Override
    public Integer update(CompanyProductIntroduction companyProductIntroduction) {
        return null;
    }

    @Override
    public Integer insert(CompanyProductIntroduction companyProductIntroduction) {
        return null;
    }

    @Override
    public void delete(Integer id) {companyProductIntroductionMapper.deleteById(id);


    }
}
